package com.jstyle.jclifexd.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.jstyle.jclifexd.BuildConfig;
import com.jstyle.jclifexd.R;
import com.jstyle.jclifexd.utils.SharedPreferenceUtils;
import com.jstyle.jclifexd.utils.Utils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ProvicyActivity extends Activity {

    @BindView(R.id.tv_proivcy)
    TextView tvProivcy;
    @BindView(R.id.iv_icon)
    ImageView ivIcon;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.bt_agree)
    Button btAgree;
    @BindView(R.id.bt_unagree)
    Button bt_unagree;
    @BindView(R.id.Read_and_agree)
    TextView Read_and_agree;
    String type = "0";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_provicy);
        ButterKnife.bind(this);
        tvProivcy.setText(Html.fromHtml(getString(R.string.provicy)));
        tvProivcy.setMovementMethod(LinkMovementMethod.getInstance());
        type = getIntent().getStringExtra("type");
  /*      if (Utils.isZh(ProvicyActivity.this)) {
            SpannableStringBuilder builder = new SpannableStringBuilder();
            String s1 = "请您仔细阅读并同意";
            SpannableString sp1 = new SpannableString(s1);
            ForegroundColorSpan fcs1 = new ForegroundColorSpan(Color.WHITE);
            ForegroundColorSpan fcs2 = new ForegroundColorSpan(Color.parseColor("#b4ad00"));
            ForegroundColorSpan fcs3 = new ForegroundColorSpan(Color.parseColor("#b4ad00"));
            sp1.setSpan(fcs1, 0, s1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//设置字体的颜色
            builder.append(sp1);//添加

            String s2 = " 《JClife应用隐私协议》";
            SpannableString sp2 = new SpannableString(s2);

            sp2.setSpan(new ClickableSpan() {
                @Override
                public void onClick(View widget) {
                    startActivity(new Intent(ProvicyActivity.this, ProvicyAboutActivity.class));
                }

                @Override
                public void updateDrawState(TextPaint ds) {
                    super.updateDrawState(ds);
                    ds.setUnderlineText(false);      //设置下划线
                }
            }, 0, s2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            sp2.setSpan(fcs2, 0, s2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//设置字体的颜色
            builder.append(sp2);//添加

            String s3 = "和";
            SpannableString sp3 = new SpannableString(s3);
            sp3.setSpan(fcs1, 0, s3.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//设置字体的颜色
            builder.append(sp3);//添加

            String s4 = "《JClife用户服务协议》";
            SpannableString sp4 = new SpannableString(s4);
            sp4.setSpan(new ClickableSpan() {
                @Override
                public void onClick(View widget) {
                    Intent intent = new Intent(ProvicyActivity.this, HeartTipsActivity.class);
                    intent.putExtra(HeartTipsActivity.TipsType, HeartTipsActivity.TipsType_Service);
                    startActivity(intent);
                }

                @Override
                public void updateDrawState(TextPaint ds) {
                    super.updateDrawState(ds);
                    ds.setUnderlineText(false);      //设置下划线
                }
            }, 0, s4.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            sp4.setSpan(fcs3, 0, s4.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//设置字体的颜色
            builder.append(sp4);//添加

            String s5 = "，如您同意，请点击“同意”开始接受我们的服务。";
            SpannableString sp5 = new SpannableString(s5);
            sp5.setSpan(fcs1, 0, s5.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//设置字体的颜色
            builder.append(sp5);//添加

            Read_and_agree.setMovementMethod(LinkMovementMethod.getInstance());
            Read_and_agree.setText(builder);
        }*/

    }

    private static final String TAG = "ProvicyActivity";

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) { //按下的如果是BACK，同时没有重复
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

    @OnClick({R.id.bt_agree, R.id.bt_unagree})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.bt_agree:
                setResult(RESULT_OK);
                SharedPreferenceUtils.setSpBoolean(SharedPreferenceUtils.KEY_Is_First, false);
                finish();
                break;
            case R.id.bt_unagree:
                SharedPreferenceUtils.setSpBoolean(SharedPreferenceUtils.KEY_Is_First, true);
                if ("0".equals(type)) {
                    System.exit(0);
                } else {
                    Intent intent = new Intent(android.content.Intent.ACTION_MAIN);
                    intent.setFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.addCategory(android.content.Intent.CATEGORY_HOME);
                    startActivity(intent);
                    System.exit(1);
                }
                break;
        }


    }
}
